#Region " Imports "

Imports BlazeApps.Library.Page
Imports BlazeApps.Library.Reports
Imports System.Data

#End Region

Partial Class Usercontrols_Options_Tools
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "

    Protected Property ItemGuid() As Guid
        Get
            Return GetGuidFromVS("ItemGuid")
        End Get
        Set(ByVal value As Guid)
            ViewState.Add("ItemGuid", value)
        End Set
    End Property

    Protected Property ItemTitle() As String
        Get
            Return GetStringFromVS("ItemTitle")
        End Get
        Set(ByVal value As String)
            ViewState.Add("ItemTitle", value)
        End Set
    End Property

    Protected Property ItemURLParams() As String
        Get
            Return GetStringFromVS("ItemURLParams")
        End Get
        Set(ByVal value As String)
            ViewState.Add("ItemURLParams", value)
        End Set
    End Property

    Public Property ItemViews() As Int64
        Get
            Return GetLongIntegerFromVS("ItemViews")
        End Get
        Set(ByVal value As Int64)
            ViewState.Add("ItemViews", value)
        End Set
    End Property

    Public Property ItemComments() As Int64
        Get
            Return GetLongIntegerFromVS("ItemComments")
        End Get
        Set(ByVal value As Int64)
            ViewState.Add("ItemComments", value)
        End Set
    End Property

    Public Property PageID() As Integer
        Get
            Return GetIntegerFromVS("PageID")
        End Get
        Set(ByVal value As Integer)
            ViewState.Add("PageID", value)
        End Set
    End Property

    Public Property PageRevision() As Integer
        Get
            Return GetIntegerFromVS("PageRevision")
        End Get
        Set(ByVal value As Integer)
            ViewState.Add("PageRevision", value)
        End Set
    End Property

    Public Property EditedDate() As String
        Get
            Return GetStringFromVS("EditedDate")
        End Get
        Set(ByVal value As String)
            ViewState.Add("EditedDate", value)
        End Set
    End Property

    Public Property PageViews() As Int64
        Get
            Return GetLongIntegerFromVS("PageViews")
        End Get
        Set(ByVal value As Int64)
            ViewState.Add("PageViews", value)
        End Set
    End Property

    Public Property PageComments() As Int64
        Get
            Return GetLongIntegerFromVS("PageComments")
        End Get
        Set(ByVal value As Int64)
            ViewState.Add("PageComments", value)
        End Set
    End Property

    Public Property HideData() As Boolean
        Get
            Return GetBooleanFromVS("HideData")
        End Get
        Set(ByVal value As Boolean)
            ViewState.Add("HideData", value)
        End Set
    End Property

#End Region

#Region " Page Events "

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        GetQueryStringValues()
        LoadToolData()

        Me.uxViewedLabel.Text = FormatViews(ItemViews)
        Me.uxCommentsLinkLabel.Text = FormatComments(ItemComments)

    End Sub

#End Region

#Region " Save Data "



#End Region

#Region " Load Data "

    Private Sub LoadToolData()
        If Not HideData Then
            Dim Item As New ReportList

            For Each row As DataRow In Item.GetRSSByItem(ItemGuid).Tables(0).Rows
                ItemTitle = CType(row("title"), String)
                ItemURLParams = CType(row("urlparams"), String)
                ItemViews = CType(row("views"), Int64)
                ItemComments = CType(row("comments"), Int64)
            Next
        End If
    End Sub

#End Region

#Region " Form Controls Events "

    Protected Sub uxEmailLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxEmailLinkButton.Click
        LoadEmail()
    End Sub

    Protected Sub uxEmailImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles uxEmailImageButton.Click
        LoadEmail()
    End Sub

    Protected Sub uxPrintMeImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles uxPrintMeImageButton.Click
        PrintMe()
    End Sub

    Protected Sub uxPrintMeLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxPrintMeLinkButton.Click
        PrintMe()
    End Sub

    Protected Sub uxDiggItImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles uxDiggItImageButton.Click
        DiggIt()
    End Sub

    Protected Sub uxDiggItLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxDiggItLinkButton.Click
        DiggIt()
    End Sub

    Protected Sub uxReddItImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles uxReddItImageButton.Click
        ReddIt()
    End Sub

    Protected Sub uxReddItLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxReddItLinkButton.Click
        ReddIt()
    End Sub

    Protected Sub uxItemFeedImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles uxItemFeedImageButton.Click
        RSSFeed()
    End Sub

    Protected Sub uxItemFeedLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxItemFeedLinkButton.Click
        RSSFeed()
    End Sub

#End Region

#Region " Helpers and Methods "

    Protected Sub GetQueryStringValues()
        ItemGuid = GetGuidFromQueryString("id")
    End Sub

    Private Sub LoadEmail()

        If UseClientEmail = True Then

            Dim EmailBody As New StringBuilder

            EmailBody.Append(Resources.Resource.DoNotEdit.ToString)
            EmailBody.Append("%0D")
            EmailBody.Append("%0D")
            EmailBody.Append(Resources.Resource.AutoGeneratedEmail.ToString)
            EmailBody.Append("%0D")
            EmailBody.Append("%0D")
            EmailBody.Append(Server.UrlEncode(String.Format("http://{0}{1}{2}", Request.ServerVariables("HTTP_HOST"), Request.ServerVariables("URL"), ItemURLParams)))
            EmailBody.Append("%0D")
            EmailBody.Append("%0D")
            EmailBody.Append(Resources.Resource.EditsCanBegin.ToString)

            SendMailUsingClient("", String.Format("Emailing Item: {0}", ItemTitle).ToString, EmailBody.ToString)

        Else
            ScriptManager.RegisterStartupScript(uxEmailLinkButton, Me.GetType(), "email", "fPopUpWin('" & String.Format("{0}.aspx?pid=msg_email&popup=1&mailarticle=1&id={1}", AppPage, ItemGuid.ToString) & "','email',0 , 0, 0,795,595, 0);", True)
        End If
    End Sub

    Private Sub PrintMe()
        ScriptManager.RegisterStartupScript(uxPrintMeImageButton, Me.GetType(), "printme", "fPopUpWin('" & String.Format("{0}.aspx{1}&printme=1", AppPage, ItemURLParams) & "','preview',1 , 1, 1,795,595, 0);", True)
    End Sub

    Private Sub DiggIt()
        ScriptManager.RegisterStartupScript(uxPrintMeImageButton, Me.GetType(), "diggit", "fPopUpWin('" & String.Format("http://www.digg.com/submit?url=http://{0}{1}{2}", Request.ServerVariables("HTTP_HOST"), Request.ServerVariables("URL"), ItemURLParams) & "','diggit',1 , 1, 1,795,595, 0);", True)
    End Sub

    Private Sub ReddIt()
        ScriptManager.RegisterStartupScript(uxPrintMeImageButton, Me.GetType(), "reddit", "fPopUpWin('" & String.Format("http://reddit.com/submit?url=http://{0}{1}{2}", Request.ServerVariables("HTTP_HOST"), Request.ServerVariables("URL"), ItemURLParams) & "','reddit',1 , 1, 1,795,595, 0);", True)
    End Sub

    Private Sub RSSFeed()
        ScriptManager.RegisterStartupScript(uxPrintMeImageButton, Me.GetType(), "rss", "fPopUpWin('" & String.Format("http://{0}{1}feeds/ItemFeed.aspx?id={2}", Request.ServerVariables("HTTP_HOST"), WebBase.AppPath, ItemGuid) & "','rss',1 , 1, 1,795,595, 0);", True)
    End Sub

#End Region

End Class
